<?php
// +----------------------------------------------------------------------
// | quanli team
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2020 http://www.fistforward.com/ All rights reserved.
// +----------------------------------------------------------------------
// | Author: create by allen.qiang
// +----------------------------------------------------------------------

/**
 * 组织机构
 * @package  quanliadmin/app/action
 * @author   create by allen.qiang
 */

quanli_require('module/base/system/sysDepartment.class.php');

class pa_userDepartment {

    public function execute(){

        global $G_PGLOB;
        if (isset($_REQUEST['operFlg']) && is_numeric($_REQUEST['operFlg'])) {

            switch ($_REQUEST['operFlg']) {
                case 1:
                    $this->showUserDepartment();
                    break;
                default:
                    $G_PGLOB->smarty->assign('msg', '参数错误，请审核后再操作');
                    $G_PGLOB->smarty->display('comm/error.tpl');
            }

        }


    }

    /**
     * 显示部门机构列表
     *
     */
    private function showUserDepartment () {

        global $G_PGLOB;

        //实例部门类
        $sysDepartment = new sysDepartment();

        //部门数据
        $department_array = array();

        //递归查询部门数据
        $sysDepartment->searchDepartment( $department_array );

        //生成html代码
        $department_html = '';
        $sysDepartment->createDepartmentListHtml( $department_array, $department_html );

        //生成下拉框html代码
        $department_select_html = '';
        $sysDepartment->createDepartmentSelectOptionHtml( $department_array, $department_select_html );

        $G_PGLOB->smarty->assign('department_html', $department_html);
        $G_PGLOB->smarty->assign('department_select_html', $department_select_html);
        $G_PGLOB->smarty->display('system/userDepartmentList.tpl');

    }


    //递归查询部门方法
    private function getUserDepartment(&$department_array,$parentID=0){
        global $G_PGLOB;

        $search_sql = " ";
        $data =  $G_PGLOB->DBCA->stmt_query($search_sql,'i',$parentID);
        $department_array = $data;
        if($data){
            foreach( $data as $key=>$val ){
                if($val->parentID){
                    $department_array[$key]['subclass'] = $this->getUserDepartment($department_array,$val['parentID']);
                }

            }
        }
    }

}